class Course < ActiveRecord::Base

  has_many :grades
  has_many :users, through: :grades

  belongs_to :teacher, class_name: "User"

  validates :name, :course_type, :course_time, :course_week,
            :class_room, :credit, :teaching_type, :exam_type, presence: true, length: {maximum: 50}

  # Yue's search code
  def self.search(search)
    if Rails.env.development?
      where("name LIKE ?", "%#{search}%") 
    elsif Rails.env.production?
      where("name ILIKE ?", "%#{search}%") 
    end
  end

end